// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from "vue";
import App from "./App";
import router from "./router";
import axios from "./utils/axiosHttp";
import store from "./store";
import ElementUI from "element-ui";
import "element-ui/lib/theme-default/index.css";

Vue.config.productionTip = false;

Vue.prototype.$http = axios;
Vue.use(ElementUI);

// 全局路由守卫
router.beforeEach((to, from, next) => {
  //console.log("global", from, to);
  if (to.meta.auth) {
    if (store.getters.isLogin) {
      next();
    } else {
      console.log("remove 1token");
      sessionStorage.clear();
      next({
        path: "/login",
        query: {
          redirect: to.fullPath
        }
      });
    }
  } else {
    next();
  }
});

console.log("router", router);

/* eslint-disable no-new */
new Vue({
  el: "#app",
  router,
  axios,
  store,
  template: "<App/>",
  components: {
    App
  }
});
